package com.youxin.busfoundation.bean;

import com.youxin.foundation.utils.ExceptionUtils;

/**
 * 输出信息和对应的code
 * @author yingde.cao
 *
 */
public class ResponseMessage {
	private String msg;
	private int code;
	
	public ResponseMessage(int code,String message) {
		this.code=code;
		this.msg=message;
	}
	
	public static ResponseMessage instance(int code,String message)
	{
		return new ResponseMessage(code,message);
	}
	
	public static ResponseMessage systemError(Throwable e)
	{
		String exString=ExceptionUtils.getStackTrace(e);
		return ResponseMessage.instance(BusinessMessages.FAILURE_CODE,exString);
	}
	
	public static ResponseMessage userFailure(String message)
	{
		return ResponseMessage.instance(BusinessMessages.USERFAILURE_CODE,message);
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof ResponseMessage)
		{
			ResponseMessage tMessage=(ResponseMessage)obj;
			return this.code==tMessage.code;			
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return Integer.valueOf(this.code).hashCode();
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}
	
}
